package servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.DBHelper;

/**
 * Servlet implementation class ProvideJob
 */
@WebServlet("/ProvideJob")
public class ProvideJob extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProvideJob() {
        super();
        // TODO Auto-generated constructor stub
    }
    protected void handProvideJob(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    	try{
    		
    		HttpSession session=request.getSession();
    		
    		String name=request.getParameter("company");
    		String salary=request.getParameter("salary");
    		String address=request.getParameter("address");
    		String companysize=request.getParameter("companysize");
    		String companytype=request.getParameter("companytype");
    		String jobtype=request.getParameter("jobtype");
    		String provider= session.getAttribute("user").toString();
    		String id="";
    		Connection con=DBHelper.getConnection();
    		PreparedStatement ps=DBHelper.getprepareStatement(con,"insert into providejob (jobid,company,salary,address,companysize,companytype,jobtype,provider)values(?,?,?,?,?,?,?,?)");
    		ps.setString(1, id);
    		ps.setString(2, name);
    		ps.setString(3,salary);
    		ps.setString(4, address);
    		ps.setString(5,companysize);
    		ps.setString(6,companytype);
    		ps.setString(7,jobtype);
    		ps.setString(8,provider);
    		ps.executeUpdate();
    		ps.close();
    		con.close();
    		}catch(Exception e){
    			e.printStackTrace();
    		}
    	request.getRequestDispatcher("ViewProvide").forward(request, response);
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		handProvideJob(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		handProvideJob(request,response);
	}

}
